cmake_minimum_required(VERSION 3.10)
project(demo #[[VERSION 1.0.0]] LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)

set(CMAKE_VERBOSE_MAKEFILE ON)

# 定义项目版本号宏
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)

set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
set(PROJECT_NAME "demo")

# 打印版本号
message(STATUS "项目版本号：${PROJECT_VERSION}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17" )
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WIN32_WINNT=0x0600")

add_compile_definitions(
        PROJECT_VERSION="${PROJECT_VERSION}"
        PROJECT_NAME="${PROJECT_NAME}"
)

include_directories(
        ${CMAKE_CURRENT_SOURCE_DIR}/src/
        ${CMAKE_CURRENT_BINARY_DIR}
)

file(GLOB_RECURSE source_files ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)

list(SORT source_files)

message(STATUS "---------------------The following is the sorted source file---------------------")
foreach (_filepath ${source_files})
    message(STATUS ${_filepath})
endforeach ()
message(STATUS "---------------------------------------------------------------------------------")

#if (WIN32)
#    set(VERSIONINFO_RC "${CMAKE_BINARY_DIR}/versioninfo.rc")
#    configure_file("${CMAKE_SOURCE_DIR}/versioninfo.rc.in" "${VERSIONINFO_RC}")
#endif ()

add_executable(demo ${source_files} ${VERSIONINFO_RC})

set_target_properties(demo PROPERTIES
        VERSION ${PROJECT_VERSION}
        OUTPUT_NAME "demo-${PROJECT_VERSION}"
)

if (MSVC)
    target_link_options(demo PRIVATE "/VERSION:${PROJECT_VERSION}")
endif ()

configure_file(
        "${CMAKE_CURRENT_SOURCE_DIR}/version.h.in"
        "${CMAKE_CURRENT_BINARY_DIR}/version.h"
        @ONLY
)

#install(TARGETS demo DESTINATION "lib/myproject-${PROJECT_VERSION}")
